home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9236 < prev    next >
Encoding:
Text File  |  1996-08-05  |  957 b   |  53 lines

  1. Path: lovage.lerc.nasa.gov!edfollo
  2. From: edfollo@lovage.lerc.nasa.gov (Jeff Follo)
  3. Newsgroups: comp.lang.c++
  4. Subject: Help -- Problem with Protected Class in Borland 4.5
  5. Date: 29 Feb 1996 15:08:13 GMT
  6. Organization: NASA Lewis Research Center
  7. Distribution: world
  8. Message-ID: <4h4fgt$ina@sulawesi.lerc.nasa.gov>
  9. NNTP-Posting-Host: lovage.lerc.nasa.gov
  10.  
  11.  
  12. I'm using Borland C++ 4.5, trying to create either a DOS target or a EasyWin
  13. target.  I cannot get the following code to compile:
  14.  
  15. #include <iostream.h>
  16.  
  17. class BaseClass
  18. {
  19.    public:
  20.       int a;
  21.    protected:
  22.       int b;
  23. };
  24.  
  25.  
  26. class UpperClass : public BaseClass
  27. {
  28.    public:
  29.       void print_a() {cout << "\na = " << a;}
  30.       void print_b() {cout << "\nb = " << b;}
  31. };
  32.  
  33. void main()
  34. {
  35.    UpperClass x;
  36.  
  37.    x.a = 1;
  38.    x.b = 2;
  39.  
  40.    x.print_a();
  41.    x.print_b();
  42.  
  43. }
  44.  
  45.  
  46. The error I get is:
  47.  
  48. 'BaseClass::b' is not accessible in function main()
  49.  
  50.  
  51. The code works if I comment out protected. What's wrong here?
  52.  
  53.